// appUserRoute-用户模块相关接口
const {
	SuccessModel,
	ErrorModel,
  AuthErrorModel
} = require("../../model/responseModel");

const { 
  appLoginCheck, 
  loginFun, 
  siginUpFun,
  getAppUserFun
} = require('../../controllers/appUser.controller');
const { md5 } = require('../../extend/utils');

const appUserRoute = async (req, res) => {
	const method = req.method;
	const bodyData = req.body;
	const headers = req.headers;

  /**
   * * 管理员登录
  */
  if (method === 'POST' && req.path === '/app/v1/api/login') {
    try {
      const username =  bodyData.username || '';
      const password = md5(bodyData.password) || '';
      const loginPromise = loginFun(username, password);
      return loginPromise.then(bodyData => {
        if (bodyData) {
          return new SuccessModel(bodyData);
        } else {
          return new ErrorModel('登录失败,请检查账号密码');
        }
      });
    } catch(e) {
      return new ErrorModel('登录失败,请检查账号密码');
    }
  }

  
}

module.exports = appUserRoute;
